package com.idroc.coelacanth.core.message.support;

import org.jboss.netty.buffer.ChannelBuffer;

import com.idroc.coelacanth.core.message.AbstractMessage;

/**
 * 字符串消息
 * @author yuyoo (yuyoo4j@163.com)
 * @date 2009-12-4 下午03:52:02
 */
public class StringMessage extends AbstractMessage {
	
	private String content = null;

	@Override
	public void decode(ChannelBuffer ib) {

		byte[] buffer = new byte[ib.readableBytes()];
		ib.readBytes(buffer);
		content = new String(buffer);
	}

	@Override
	public void encode(ChannelBuffer ob) {
		 
		ob.writeBytes(content.getBytes());
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Override
	public String toString() { 
		
		StringBuilder sb = new StringBuilder();
		sb.append("StringMessage[");
		sb.append("sn:").append(this.getSN()).append(",");
		sb.append("content:").append(content);
		sb.append("]"); 
		return sb.toString();
	} 
}
